// import './index.scss';
import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
// import Http from "../../common/http";

export default {
  name: 'oneToOneDonation',
  data () {
    return {
      index: 0,
      // 信息反馈是否有红点  为''的时候没有  为' '的时候有
      isXinxi: ' ',
      userId: '',
      item: 'item',
      textMoney: '',
      checkOK: true,
      isA: true,
      threshold: 50,
      minmovingdistance: 30,
      // 项目id
      event_id: '',
      // 显示哪一个模块
      pageNoOther: 1,
      pageNoJuankuan: 1,
      lookMore: '查看更多',
      lookMoreJuankuans: '查看更多',
      pageNo: 1,
      pageSize: 5,
      pageSizeN: 1,
      witchShow: 'xiangqing',
      eventAll: {},
      eventOther: [],
      eventJuankuan: [],
      isDoing: '进行中',
      eventL: {
        helpName: '',
        eventName: '',
        organizationName: '',
        eventPicUrl: '',
        helpWay: ''
      },
      isID: function (value) {
        let r = /^(\d{18}|\d{17}x)$/;
        if (r.test(value)) {
          return {
            valid: true,
            msg: '身份证正确'
          }
        } else {
          return {
            valid: false,
            msg: '身份证错误'
          }
        }
      }
    }
  },
  mounted () {
    this.userId = window.sessionStorage.getItem('userId')
    // this.event_id = window.sessionStorage.getItem('event_id')
    this.mountedH()
  },
  methods: {
    lastEven () {
      this.pageNo--
      if (this.pageNo <= 0) {
        this.pageNo = 1
        return
      }
      this.mountedH()
    },
    nextEven () {
      this.pageNo++
      this.mountedH()
    },
    mountedH () {
      http.post(CONSTANT.EVENT_BUUNIQUE, {pageNo: this.pageNo, pageSize: this.pageSizeN}, (res) => {
        console.log(res)
        if (res.code == 200) {
          if (res.errmsg == '没有更多的项目') {
            this.pageNo--
            return
          }
          this.eventL = res.list[0]
          window.sessionStorage.setItem('event_id', this.eventL.id)
          this.event_id = this.eventL.id
          if (this.eventL.eventStatus == 1) {
            this.isDoing = '进行中'
          } else if (this.eventL.eventStatus == 4) {
            this.isDoing = '已结束'
          }
          http.post(CONSTANT.EVENT_VIEW, {event_id: this.eventL.id}, (res) => {
            console.log(res)
            this.eventAll = res.obj
            if (res.obj.feedBack == '') {
              this.isXinxi = ''
            }
          })
          this.OtherProjects();
          this.OtherJuankuans();
        }
      })
    },
    moreOtherJuankuans () {
      // 查看更多捐款
      this.pageNoJuankuan++;
      this.OtherJuankuans()
    },
    OtherJuankuans () {
      // 捐款记录
      http.post(CONSTANT.EVENT_DONATE, {
        event_id: this.event_id,
        pageNo:this.pageNoJuankuan,
        pageSize:this.pageSize
      }, (res) => {
        if (res.errmsg == '没有更多的项目') {
          this.pageNoJuankuan--
          this.lookMoreJuankuans = '没有更多的捐款记录了'
          return
        } else if (res.errmsg == '') {
          if (this.pageNoJuankuan == 1) {
            this.eventJuankuan = res.list
          } else {
            this.eventJuankuan = this.eventJuankuan.concat(res.list)
          }
        }
      })
    },
    moreOtherProjects () {
      // 查看更多该单位项目
      this.pageNoOther++;
      this.OtherProjects()
    },
    OtherProjects () {
      // 单位发起的项目
      http.post(CONSTANT.EVENT_ORGANIZE, {
        event_id: this.event_id,
        pageNo:this.pageNoOther,
        pageSize:this.pageSize
      }, (res) => {
        // console.log('发起项目')
        // console.log(res)
        if (res.code == 200) {
          if (res.errmsg == '没有更多的项目') {
            this.pageNoOther--
            this.lookMore = '没有更多的项目了'
            return
          } else if (res.errmsg == '') {
            if (this.pageNoOther == 1) {
              this.eventOther = res.list
            } else {
              this.eventOther = this.eventOther.concat( res.list)
            }
          }
        }
      })
    },
    OtherJuankuans () {
      // 捐款记录
      http.post(CONSTANT.EVENT_DONATE, {
        event_id: this.event_id,
        pageNo:this.pageNoJuankuan,
        pageSize:this.pageSize
      }, (res) => {
        if (res.errmsg == '没有更多的项目') {
          this.pageNoJuankuan--
          this.lookMoreJuankuans = '没有更多的捐款记录了'
          return
        } else if (res.errmsg == '') {
          if (this.pageNoJuankuan == 1) {
            this.eventJuankuan = res.list
          } else {
            this.eventJuankuan = this.eventJuankuan.concat(res.list)
          }
        }
      })
    },
    wantJuank () {
      // 我要捐款
      this.$router.push({path: '/oneToOneDetails'})
    },
    goPayment () {
      this.$router.push({path: '/payment', query: {witchOne: 'geren', money: this.eventL.eventGoalAmount}})
    },
    comeBack () {
      window.history.go(-1)
    }
  }
}
